name: "MkDocs Publish Docs on GitHub Pages CI"
on:
  # Manually trigger workflow
  workflow_dispatch:
    inputs:
      branch:
        description: Build MkDocs from Branch (Optional)
        required: false
  # Trigger when a push happens 
  # to select branches.
  push:
    branches:
      - master
      - main
      #- add_mkdocs_workflow

env:
  PYTHON_VERSION: "3.9"
  USER_SPECIFIED_BRANCH: ${{ github.event.inputs.branch }}

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Set up Python runtime
        uses: actions/setup-python@v2
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Install Python dependencies for MkDocs
        run: |
          # pip install -r requirements/docs.txt
          pip install mkdocs-material

      - name: Deploy documentation
        env:
          FONTAWESOME_KIT: ${{ secrets.FONTAWESOME_KIT }}
        run: |
          # Check if user-provided branch exists and 
          # then switch to that branch.
          if [[ -z $(git branch --list "${{ env.USER_SPECIFIED_BRANCH }}") ]]; \
            then (\
              echo "Switching to branch: ${{ env.USER_SPECIFIED_BRANCH }}" && \
              git checkout ${{ env.USER_SPECIFIED_BRANCH }} \
            ); else USER_SPECIFIED_BRANCH=${GITHUB_REF##*/} ; fi && \
          echo "Current Git Branch: ${USER_SPECIFIED_BRANCH}"
          
          # Begin Deploying MkDocs
          mkdocs gh-deploy --force
          mkdocs --version
